package com.example.park

import android.graphics.Color
import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.ParkEntityItem
import com.example.park.databinding.ItemParkBinding

class ParkAdapter:BaseQuickAdapter<ParkEntityItem,BaseViewHolder>(R.layout.item_park) {

    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemParkBinding>(viewHolder.itemView)
    }

    override fun convert(helper: BaseViewHolder, item: ParkEntityItem) {
        val  binding = DataBindingUtil.getBinding<ItemParkBinding>(helper.itemView)
        binding?.info = item
        binding?.parkSpaceStatus?.apply {
            when(item.spaceStatus){
                "空闲"->{
                    this.setTextColor(Color.WHITE)
                    this.setBackgroundResource(R.drawable.bg_green)
                }
                "占用"->{
                    this.setTextColor(Color.WHITE)
                    this.setBackgroundResource(R.drawable.bg_red)
                }
                "维护中"->{
                    this.setTextColor(Color.WHITE)
                    this.setBackgroundResource(R.drawable.bg_yellow)
                }
                else->{
                    this.setTextColor(Color.WHITE)
                    this.setBackgroundResource(R.drawable.bg_yellow)
                }
            }
        }
    }
}